package com.example.demo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.demo.domain.entity.PermissionFrontUrl;
import com.example.demo.domain.entity.RolePermission;
import com.example.demo.domain.entity.TrainClassUser;
import com.example.demo.exception.ValidatorException;
import com.example.demo.mapper.RolePermissionMapper;
import com.example.demo.param.PersionParam;
import com.example.demo.param.RolePersionParam;
import com.example.demo.service.PermissionFrontUrlService;
import com.example.demo.mapper.PermissionFrontUrlMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
*
*/
@Service
public class PermissionFrontUrlServiceImpl extends ServiceImpl<PermissionFrontUrlMapper, PermissionFrontUrl>
implements PermissionFrontUrlService{

    @Resource
    private PermissionFrontUrlMapper permissionFrontUrlMapper;

    @Resource
    private RolePermissionMapper rolePermissionMapper;

    @Override
    public Page<PermissionFrontUrl> queryAllPermissionFrontUrl(PersionParam persionParam) {
        QueryWrapper<PermissionFrontUrl> queryWrapper = new QueryWrapper<>();
        Page<PermissionFrontUrl> page = new Page<>(persionParam.getPageNumber(), persionParam.getPageSize());
        return permissionFrontUrlMapper.selectPage(page,queryWrapper);
    }

    @Override
    public Page<RolePermission> queryRolePermission(RolePersionParam rolePersionParam) {
        QueryWrapper<RolePermission> queryWrapper = new QueryWrapper<>();
        if (null == rolePersionParam.getRoleId()){
            throw new ValidatorException("角色id不能为空");
        }
        queryWrapper.eq("role_id",rolePersionParam.getRoleId());
        Page<RolePermission> page = new Page<>(rolePersionParam.getPageNumber(), rolePersionParam.getPageSize());
        return rolePermissionMapper.selectPage(page,queryWrapper);
    }
}
